import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class InputFieldExps extends StatelessWidget {
  const InputFieldExps({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(child:
        Column(
          children: [
            TextField(
              keyboardType: TextInputType.emailAddress,
              inputFormatters: [
                FilteringTextInputFormatter.deny(RegExp(r'\s')), // 直接禁止空格
                // 或者只允许邮箱合法字符
                FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z0-9@._-]')),
              ],
              decoration: const InputDecoration(
                labelText: 'Email',
                hintText: 'example@domain.com',
              ),
            )
          ],
        )
      ),
    );
  }
}
